﻿/*-------------------------------------------------------------------------
* 命名空间: SiliconSelect.ViewModels/AlarmSettingViewModel
* 类       名: AlarmSettingViewModel
* 功      能:  报警信息设置表,所有的报警信息的设置都在这个表中.
* 时      间:  2023/9/22 15:22:06
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using SiliconSelect.Base;
using SiliconSelect.BLL;
using SiliconSelect.Common;
using SiliconSelect.DAL.DataEntity;
using SiliconSelect.Models;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SiliconSelect.ViewModels
{
    public class AlarmSettingViewModel : NotifyBase
    {

        public AlarmSettingViewModel()
        {
            RefreshDataTask();
        }

        /// <summary>
        /// 报警设置对应的数据源
        /// </summary>
        private ObservableCollection<AlarmSettingModel>? _alarmSettingList = new ObservableCollection<AlarmSettingModel>();
        public ObservableCollection<AlarmSettingModel>? AlarmSettingList
        {
            get { return _alarmSettingList; }
            set { SetProperty(ref _alarmSettingList, value); }
        }

        /// <summary>
        /// 对报警信息的数据进行刷新.
        /// </summary>
        public void RefreshDataTask()
        {
            DataResult<List<AlarmSettingEntity>> result = LocalDataAccess.GetAlarmSettings();
            if (!result.State)
            {
                if (result.Data != null && result.Data.Count > 0)
                {
                    AlarmSettingList!.Clear();
                    foreach (var data in result.Data!)
                    {
                        var model = new AlarmSettingModel();
                        model.Id = data.Id;
                        model.AlarmCode = data.AlarmCode;
                        model.Content = data.Content;
                        model.SolutionHelp = data.SolutionHelp;
                        AlarmSettingList?.Add(model);
                    }
                }
            }
            else
            {
                LogHelper.WriteLog(LogType.Exception, result.Message);
                MessageBox.Show("数据库操作异常,报警设置表获取失败!", "数据库操作异常提示框", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

    }
}
